from flask import Flask
from cofing import DevConfig, PorConfig
from os import environ

from db_init import db,Migrate


def creat_flask():
    # 2.实例化Flask对象
    app = Flask(__name__)

    # 判断环境
    if environ.get("my_env") == "dev":
        my_config = DevConfig
    else:
        my_config = PorConfig

    # 加载 配置文件
    app.config.from_object(my_config)
    db.init_app(app)
    migrate = Migrate()
    migrate.init_app(app=app, db=db)
    return app
